package com.scorekeeper.ui;

import java.util.List;

import com.scorekeeper.R;

import android.app.ListFragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class StandingsListFragment extends ListFragment {
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Bundle args = this.getArguments();
		
		setListAdapter(new StandingsListAdapter(getActivity(), 
			android.R.layout.simple_selectable_list_item, args.getStringArrayList("teamNames")));
	}
	
	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {

	}
	
	public class StandingsListAdapter extends ArrayAdapter<String>  {
		private List<String> items;
		private LayoutInflater mInflater;
		
		public StandingsListAdapter(Context context, int textViewResourceId, List<String> objects) {
			super(context, textViewResourceId, objects);
			
			mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			
			items = objects;
		}
		
		@Override
		public int getCount() {
			return items.size();
		}
		
		@Override
		public String getItem(int position) {
			return items.get(position);
		}
		
		@Override
		public long getItemId(int position) {
			return position;
		}
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			View v = convertView;
			
			if (v == null) {
				v = mInflater.inflate(R.layout.team_row, null) ;
			} 
			
			((TextView)v.findViewById(R.id.team_row_pos)).setText(Integer.toString(position + 1));
			((TextView)v.findViewById(R.id.team_row_name)).setText(items.get(position));
			
			//redraw
			parent.refreshDrawableState();
            
			return v;
		}
	}
}